-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion of new function: describe_missing()
#561
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I think it would be good to have describe_missing()
but the way it is implemented and documented looks very field-specific to me. I find the output of skimr::skim()
easier to understand with n_missing
and complete_rate
for instance. I'm also not familiar at all with aggregating stats on missing values across several variables (e.g. Ozone:Wind
) and the default output looks unexpected to me (I'd rather expect one row per variable).
#' @description Provides a detailed description of missing values in a data frame. | ||
#' This function reports both absolute and percentage missing values of specified | ||
#' column lists or scales, following recommended guidelines. Some authors recommend | ||
#' reporting item-level missingness per scale, as well as a participant's maximum | ||
#' number of missing items by scale. For example, Parent (2013) writes: | ||
#' | ||
#' *I recommend that authors (a) state their tolerance level for missing data by scale | ||
#' or subscale (e.g., "We calculated means for all subscales on which participants gave | ||
#' at least 75% complete data") and then (b) report the individual missingness rates | ||
#' by scale per data point (i.e., the number of missing values out of all data points | ||
#' on that scale for all participants) and the maximum by participant (e.g., "For Attachment | ||
#' Anxiety, a total of 4 missing data points out of 100 were observed, with no participant | ||
#' missing more than a single data point").* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds a bit too much focused on survey data while this function can be interesting for all kinds of data. I'd rather keep the first or two first sentences here and move the rest in a specific section in 'Details' (but even there, this seems very field-specific).
#' missing more than a single data point").* | ||
#' | ||
#' @param data The data frame to be analyzed. | ||
#' @param vars Variable (or lists of variables) to check for missing values (NAs). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use select
, exclude
, etc. in all other dataframe functions, I think we should here as well.
#' | ||
#' @param data The data frame to be analyzed. | ||
#' @param vars Variable (or lists of variables) to check for missing values (NAs). | ||
#' @param scales The scale names to check for missing values (as a character vector). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this description of scales
unclear, can you detail a bit more?
#' @param data The data frame to be analyzed. | ||
#' @param vars Variable (or lists of variables) to check for missing values (NAs). | ||
#' @param scales The scale names to check for missing values (as a character vector). | ||
#' @keywords missing values NA guidelines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never really understood the point of @keywords
(apart from @keywords internal
), where do they appear in the docs?
#' @keywords missing values NA guidelines | ||
#' @return A dataframe with the following columns: | ||
#' - `var`: Variables selected. | ||
#' - `items`: Number of items for selected variables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think unique_values
instead of items
would be clearer.
#' - `na`: Number of missing cell values for those variables (e.g., 2 missing | ||
#' values for the first participant + 2 missing values for the second participant | ||
#' = total of 4 missing values). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds again very field-specific, I think we could keep it simple:
#' - `na`: Number of missing cell values for those variables (e.g., 2 missing | |
#' values for the first participant + 2 missing values for the second participant | |
#' = total of 4 missing values). | |
#' - `na`: Number of missing values for those variables. |
#' # One can list the scale names directly: | ||
#' describe_missing(df, scales = c("ID", "open", "extrovert", "agreeable")) | ||
describe_missing <- function(data, vars = NULL, scales = NULL) { | ||
classes <- lapply(data, class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never used.
Fixes #454